package com.example.protobufdemo;

import java.util.HashMap;
import java.util.Map;

/**
 * 广告信息实体类
 * @author Administrator
 *
 */
public class MyADInfo {

	MyAdInf _myAdInf = null;
	
	public static MyADInfo _adInfo;
	public MyADInfo(){
		if (adinfoMap == null) {
			adinfoMap = new HashMap<>();
		}
	}
	public static MyADInfo getAdInfoInstance(){
		if (_adInfo == null) {
			_adInfo = new MyADInfo();
		}
		return _adInfo;
	}
	
	public Map<Integer, MyAdInfoBeanSingle> adinfoMap;//弹出广告集合
	
	/**
	 * 添加广告信息
	 * @param picUrl
	 * @param apkUrl
	 */
	public void addADInfo(int index, String picUrl, String apkUrl){
		if (adinfoMap == null) {
			return;
		}
		
		MyAdInfoBeanSingle adinfoSingle = adinfoMap.get(index);
		if (adinfoSingle == null) {
			adinfoSingle = new MyAdInfoBeanSingle();
			adinfoMap.put(index, adinfoSingle);
		}
		
		adinfoSingle.adIndex = index;
		adinfoSingle.adApkUrl = apkUrl;
		adinfoSingle.adPicUrl = picUrl;
		
		if (_myAdInf != null) {
			_myAdInf.receiverAdInf(adinfoSingle);
		}
		
	}
	
	public void getADInfo(MyAdInf adInf){
		if (adInf == null || adinfoMap == null) {
			return;
		}
		_myAdInf = adInf;
		
		for (Map.Entry<Integer, MyAdInfoBeanSingle> entry : adinfoMap.entrySet()) {
			MyAdInfoBeanSingle adSingle = entry.getValue();
			_myAdInf.receiverAdInf(adSingle);
		}
	}
	
	
	
	/**
	 * 单个广告信息
	 * @author Administrator
	 *
	 */
	public class MyAdInfoBeanSingle{
		int adIndex; //广告序号
		String adPicUrl;//广告图片地址
		String adApkUrl;//广告apk地址
		public String getAdPicUrl() {
			return adPicUrl;
		}
		public void setAdPicUrl(String adPicUrl) {
			this.adPicUrl = adPicUrl;
		}
		public String getAdApkUrl() {
			return adApkUrl;
		}
		public void setAdApkUrl(String adApkUrl) {
			this.adApkUrl = adApkUrl;
		}
		public int getAdIndex() {
			return adIndex;
		}
		public void setAdIndex(int adIndex) {
			this.adIndex = adIndex;
		}
		
	}
	
	//获取广告信息  接口
	public interface MyAdInf{
		public void receiverAdInf(Object object);
	}
	
}
